﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ERPStudio;
using System.Data.SqlClient;

namespace ESRP
{
    public partial class CopiazaSolduriInitialePeJurnaleFrm : FrmCard
    {
        public CopiazaSolduriInitialePeJurnaleFrm(ModuleClass mc): base(mc)
        {
            InitializeComponent();
        }

        private void CopiazaSolduriInitialePeJurnaleFrm_Load(object sender, EventArgs e)
        {
            SqlConnection con = DeschideConexiune(workConnString);
            this.jurnaleTableAdapter.Connection = con;
            this.jurnaleTableAdapter.Fill(this.eSRPDataSet.Jurnale, ModuleInfo.CodUnitate);
            InchideConexiune(con);

            AddButton("Copiaza", global::ERPStudio.Properties.Resources._001_07, StartCopy, ToolStripItemAlignment.Right, false);
        }

        private void StartCopy(object sender, EventArgs e)
        { 
            SqlConnection con = DeschideConexiune(workConnString);
            SqlCommand cmd = new SqlCommand("balcon_CopiazaSolduriInitialeCapitole",con);
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("CodUnitate",ModuleInfo.CodUnitate));
            cmd.Parameters.Add(new SqlParameter("jurnalSelectat",denumireComboBox.SelectedValue));
            try { cmd.ExecuteNonQuery(); }
            catch (Exception ex)
            {
                MessageBoxFrm mbt = new MessageBoxFrm("Eroare",ex.Message, String.Empty, MessageBoxFrm.ImaginiMB.StopIcon, null);
                mbt.AddButton("Ieşire", 70, mbt.MessageBoxFrm_Click_Yes);
                mbt.ShowDialog();
            }
            finally
            {
                InchideConexiune(con);
            }
            MessageBoxFrm mbt2 = new MessageBoxFrm("Succes", "Soldurile initiale au fost copiate cu succes!", String.Empty, MessageBoxFrm.ImaginiMB.InformareIcon, null);
            mbt2.AddButton("Ieşire", 70, mbt2.MessageBoxFrm_Click_Yes);
            mbt2.ShowDialog();
            DialogResult = System.Windows.Forms.DialogResult.OK;
            Close(); 
        }

    }
}
